import { useEffect, useState } from "react";
import { invoke } from "@tauri-apps/api/core";
import { Card, Image, List } from "tdesign-react";
import ListItem from "tdesign-react/es/list/ListItem";
import ListItemMeta from "tdesign-react/es/list/ListItemMeta";
import { Respon } from "../types";
const Home = () => {
  const [host_list, set_host_list] = useState<any>([]);
  // const update = async () => {
  //   await invoke("update_weibo");
  //   await fetchData();
  // };

  const update = async () => {
    console.log("send request");
    var respon: Respon = await invoke("get_report");
    console.log("请求成功。。。。。");
    console.log(respon);
    console.log(respon.datas);
    set_host_list(respon.datas);
  };

  // const fetchData = async () => {
  //   let result: any = await invoke("get_news_from_weibo_hot");
  //   console.log(result);
  //   set_host_list(result.data.data.cards[0].card_group);
  // };

  useEffect(() => {
    update();
  }, []);

  return (
    <div>
      <Card style={{ height: 700, width: 600 }}>
        <List size="small" style={{ height: 600, width: 500 }}>
          {host_list.map((item: any) => (
            <ListItem key={item.id}>
              <Image
                src={item.owner.avatar_url}
                shape="circle"
                style={{ height: 40, width: 40 }}
              />
              <ListItemMeta description={item.name} />
            </ListItem>
          ))}
        </List>
      </Card>
    </div>
  );
};

export default Home;
